/*
 * Copyright 2011-2013 OpenAjax Alliance
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * @file sidebar.js
 *
 * @desc Utilities to support the selection and viewing of sidebar information
 */

Components.utils.import("resource://oaa-accessibility-extension/cache-inspector-common.js");


/* ---------------------------------------------------------------- */
/*                          OAA_CI Object                           */ 
/* ---------------------------------------------------------------- */

if (typeof OAA_AE_SIDEBAR === "undefined") {
  var OAA_AE_SIDEBAR = {};
}

// import getLogger
Components.utils.import("resource://oaa-ae-utilities/logger.js", OAA_AE_SIDEBAR);


OAA_AE_SIDEBAR.OAA_VIEWS = {
   // Rule Summaries

   'SUMMARY_RULE_CATEGORIES': {
      'title'    : 'ruleSummaryCategories', 
      'option'   : OpenAjax.a11y.RULE_SUMMARY.CATEGORIES, 
      'type'     : 'summary'
    },
   'SUMMARY_WCAG20': {
      'title'  : 'ruleSummaryWCAG20', 
      'option' : OpenAjax.a11y.RULE_SUMMARY.WCAG20, 
      'type'   : 'summary'
    },
   'SUMMARY_PRINCIPLES': {
      'title'  : 'ruleSummaryPrinciples', 
      'option' : OpenAjax.a11y.RULE_SUMMARY.PRINCIPLES, 
      'type'   : 'summary'
    },
   'SUMMARY_GUIDELINES': {
      'title'  : 'ruleSummaryGuidelines', 
      'option' : OpenAjax.a11y.RULE_SUMMARY.GUIDELINES, 
      'type'   : 'summary'
    },
   'SUMMARY_SUCCESS_CRITERIA': {
      'title'  : 'ruleSummarySuccessCriteria', 
      'option' : OpenAjax.a11y.RULE_SUMMARY.SUCCESS_CRITERIA, 
      'type'   : 'summary'
    },
   'SUMMARY_RULESET_TYPE': {
      'title'  : 'ruleSummaryRulesetType', 
      'option' : OpenAjax.a11y.RULE_SUMMARY.RULESET_TYPE, 
      'type'   : 'summary'
    },    
    
   // Special Rule Categories
    'ALL_RULES': {
      'title'  : 'ruleCategoryAll', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.ALL, 
      'type'   : 'category'
    },
    
   // Rule Categories
   'AUDIO_VIDEO_RULES': {
      'title'  : 'ruleCategoryAudioVideo', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.AUDIO_VIDEO, 
      'type'   : 'category'
    },
   'FORM_CONTROL_RULES': {
      'title'  : 'ruleCategoryFormControls', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.FORMS, 
      'type'   : 'category'
    },
   'HEADING_RULES': {
      'title'  : 'ruleCategoryHeadings', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.HEADINGS, 
      'type'   : 'category'
    },
   'IMAGE_RULES': {
      'title'  : 'ruleCategoryImages', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.IMAGES, 
      'type'   : 'category'
    },
   'KEYBOARD_RULES': {
      'title'  : 'ruleCategoryKeyboardSupport', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.KEYBOARD_SUPPORT, 
      'type'   : 'category'
    },
   'LANDMARK_RULES': {
      'title'  : 'ruleCategoryLandmarks', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.LANDMARKS, 
      'type'   : 'category'
    },
   'LINK_RULES': {
      'title'  : 'ruleCategoryLinks', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.LINKS, 
      'type'   : 'category'
    },
   'NAVIGATION_RULES': {
      'title'  : 'ruleCategoryNavigation', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.SITE_NAVIGATION, 
      'type'   : 'category'
    },
   'STYLE_RULES': {
      'title'  : 'ruleCategoryStylesReadability', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.STYLES_READABILITY, 
      'type'   : 'category'
    },
   'TABLE_RULES': {
      'title'  : 'ruleCategoryDataTables', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.TABLES, 
      'type'   : 'category'
    },
   'TIMING_RULES': {
      'title'  : 'ruleCategoryTiming', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.TIMING, 
      'type'   : 'category'
    },
   'WIDGET_RULES': {
      'title'  : 'ruleCategoryWidgetsScripts', 
      'option' : OpenAjax.a11y.RULE_CATEGORIES.WIDGETS_SCRIPTS, 
      'type'   : 'category'
    },

   // WCAG 2.0 Principles 
   'PRINCIPLE_1': {
      'title'  : 'principle_1', 
      'option' : OpenAjax.a11y.WCAG20_PRINCIPLE.P_1, 
      'type'   : 'principle'
    },
   'PRINCIPLE_2': {
      'title'  : 'principle_2', 
      'option' : OpenAjax.a11y.WCAG20_PRINCIPLE.P_2, 
      'type'   : 'principle'
    },
   'PRINCIPLE_3': {
      'title'  : 'principle_3', 
      'option' : OpenAjax.a11y.WCAG20_PRINCIPLE.P_3, 
      'type'   : 'principle'
    },
   'PRINCIPLE_4': {
      'title'  : 'principle_4', 
      'option' : OpenAjax.a11y.WCAG20_PRINCIPLE.P_4, 
      'type'   : 'principle'
    },

   // WCAG 2.0 Guidelines 
   'GUIDELINE_1_1': {
      'title'  : 'guideline_1_1', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_1_1, 
      'type'   : 'guideline'
    },
   'GUIDELINE_1_2': {
      'title'  : 'guideline_1_2', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_1_2, 
      'type'   : 'guideline'
    },
   'GUIDELINE_1_3': {
      'title'  : 'guideline_1_3', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_1_3, 
      'type'   : 'guideline'
    },
   'GUIDELINE_1_4': {
      'title'  : 'guideline_1_4', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_1_4, 
      'type'   : 'guideline'
    },
   'GUIDELINE_2_1': {
      'title'  : 'guideline_2_1', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_2_1, 
      'type'   : 'guideline'
    },
   'GUIDELINE_2_2': {
      'title'  : 'guideline_2_2', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_2_2, 
      'type'   : 'guideline'
    },
   'GUIDELINE_2_3': {
      'title'  : 'guideline_2_3', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_2_3, 
      'type'   : 'guideline'
    },
   'GUIDELINE_2_4': {
      'title'  : 'guideline_2_4', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_2_4, 
      'type'   : 'guideline'
    },
   'GUIDELINE_3_1': {
      'title'  : 'guideline_3_1', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_3_1, 
      'type'   : 'guideline'
    },
   'GUIDELINE_3_2': {
      'title'  : 'guideline_3_2', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_3_2, 
      'type'   : 'guideline'
    },
   'GUIDELINE_3_3': {
      'title'  : 'guideline_3_3', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_3_3, 
      'type'   : 'guideline'
    },
   'GUIDELINE_4_1': {
      'title'  : 'guideline_4_1', 
      'option' : OpenAjax.a11y.WCAG20_GUIDELINE.G_4_1, 
      'type'   : 'guideline'
    },
    
   // WCAG 2.0 Level A Success Criteria 
   'SC_1_1_1': {
      'title'  : 'sc_1_1_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_1_1, 
      'type'   : 'success_criterion'
    },
   'SC_1_2_1': {
      'title'  : 'sc_1_2_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_1, 
      'type'   : 'success_criterion'
    },
   'SC_1_2_2': {
      'title'  : 'sc_1_2_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_2, 
      'type'   : 'success_criterion'
    },
   'SC_1_2_3': {
      'title'  : 'sc_1_2_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_3, 
      'type'   : 'success_criterion'
    },
   'SC_1_3_1': {
      'title'  : 'sc_1_3_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_3_1, 
      'type'   : 'success_criterion'
    },
   'SC_1_3_2': {
      'title'  : 'sc_1_3_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_3_2, 
      'type'   : 'success_criterion'
    },
   'SC_1_3_3': {
      'title'  : 'sc_1_3_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_3_3, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_1': {
      'title'  : 'sc_1_4_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_1, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_2': {
      'title'  : 'sc_1_4_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_2, 
      'type'   : 'success_criterion'
    },
   'SC_2_1_1': {
      'title'  : 'sc_2_1_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_1_1, 
      'type'   : 'success_criterion'
    },
   'SC_2_1_2': {
      'title'  : 'sc_2_1_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_1_2, 
      'type'   : 'success_criterion'
    },
   'SC_2_2_1': {
      'title'  : 'sc_2_2_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_2_1, 
      'type'   : 'success_criterion'
    },
   'SC_2_2_2': {
      'title'  : 'sc_2_2_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_2_2, 
      'type'   : 'success_criterion'
    },
   'SC_2_3_1': {
      'title'  : 'sc_2_3_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_3_1, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_1': {
      'title'  : 'sc_2_4_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_1, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_2': {
      'title'  : 'sc_2_4_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_2, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_3': {
      'title'  : 'sc_2_4_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_3, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_4': {
      'title'  : 'sc_2_4_4', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_4, 
      'type'   : 'success_criterion'
    },
   'SC_3_1_1': {
      'title'  : 'sc_3_1_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_1_1, 
      'type'   : 'success_criterion'
    },
   'SC_3_2_1': {
      'title'  : 'sc_3_2_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_2_1, 
      'type'   : 'success_criterion'
    },
   'SC_3_2_2': {
      'title'  : 'sc_3_2_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_2_2, 
      'type'   : 'success_criterion'
    },
   'SC_3_3_1': {
      'title'  : 'sc_3_3_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_3_1, 
      'type'   : 'success_criterion'
    },
   'SC_3_3_2': {
      'title'  : 'sc_3_3_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_3_2, 
      'type'   : 'success_criterion'
    },
   'SC_4_1_1': {
      'title'  : 'sc_4_1_1', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_4_4_1, 
      'type'   : 'success_criterion'
    },
   'SC_4_1_2': {
      'title'  : 'sc_4_1_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_4_4_2, 
      'type'   : 'success_criterion'
    },
    
   // WCAG 2.0 Level AA Success Criteria 
   'SC_1_2_4': {
      'title'  : 'sc_1_2_4', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_4, 
      'type'   : 'success_criterion'
    },
   'SC_1_2_5': {
      'title'  : 'sc_1_2_5', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_5, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_3': {
      'title'  : 'sc_1_4_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_3, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_4': {
      'title'  : 'sc_1_4_4', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_4, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_5': {
      'title'  : 'sc_1_4_5', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_5, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_5': {
      'title'  : 'sc_2_4_5', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_5, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_6': {
      'title'  : 'sc_2_4_6', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_6, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_7': {
      'title'  : 'sc_2_4_7', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_7, 
      'type'   : 'success_criterion'
    },
   'SC_3_1_2': {
      'title'  : 'sc_3_1_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_, 
      'type'   : 'success_criterion'
    },
   'SC_3_2_3': {
      'title'  : 'sc_3_2_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_2_3, 
      'type'   : 'success_criterion'
    },
   'SC_3_2_4': {
      'title'  : 'sc_3_2_4', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_2_4, 
      'type'   : 'success_criterion'
    },
   'SC_3_3_3': {
      'title'  : 'sc_3_3_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_3_3, 
      'type'   : 'success_criterion'
    },
   'SC_3_3_4': {
      'title'  : 'sc_3_3_4', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_3_4, 
      'type'   : 'success_criterion'
    },
    
   // WCAG 2.0 Level AAA Success Criteria 
   'SC_1_2_6': {
      'title'  : 'sc_1_2_6', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_6, 
      'type'   : 'success_criterion'
    },
   'SC_1_2_7': {
      'title'  : 'sc_1_2_7', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_7, 
      'type'   : 'success_criterion'
    },
   'SC_1_2_8': {
      'title'  : 'sc_1_2_8', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_8, 
      'type'   : 'success_criterion'
    },
   'SC_1_2_9': {
      'title'  : 'sc_1_2_9', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_2_9, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_6': {
      'title'  : 'sc_1_4_6', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_6, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_7': {
      'title'  : 'sc_1_4_7', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_7, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_8': {
      'title'  : 'sc_1_4_8', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_8, 
      'type'   : 'success_criterion'
    },
   'SC_1_4_9': {
      'title'  : 'sc_1_4_9', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_1_4_9, 
      'type'   : 'success_criterion'
    },
   'SC_2_1_3': {
      'title'  : 'sc_2_1_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_1_3, 
      'type'   : 'success_criterion'
    },
   'SC_2_2_3': {
      'title'  : 'sc_2_2_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_2_3, 
      'type'   : 'success_criterion'
    },
   'SC_2_2_4': {
      'title'  : 'sc_2_2_4', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_2_4, 
      'type'   : 'success_criterion'
    },
   'SC_2_2_5': {
      'title'  : 'sc_2_2_5', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_2_5, 
      'type'   : 'success_criterion'
    },
   'SC_2_3_2': {
      'title'  : 'sc_2_3_2', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_3_2, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_8': {
      'title'  : 'sc_2_4_8', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_8, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_9': {
      'title'  : 'sc_2_4_9', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_9, 
      'type'   : 'success_criterion'
    },
   'SC_2_4_10': {
      'title'  : 'sc_2_4_10', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_2_4_10, 
      'type'   : 'success_criterion'
    },
   'SC_3_1_3': {
      'title'  : 'sc_3_1_3', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_1_3, 
      'type'   : 'success_criterion'
    },
   'SC_3_1_4': {
      'title'  : 'sc_3_1_4', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_1_4, 
      'type'   : 'success_criterion'
    },
   'SC_3_1_5': {
      'title'  : 'sc_3_1_5', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_1_5, 
      'type'   : 'success_criterion'
    },
   'SC_3_1_6': {
      'title'  : 'sc_3_1_6', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_1_6, 
      'type'   : 'success_criterion'
    },
   'SC_3_2_5': {
      'title'  : 'sc_3_2_5', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_2_5, 
      'type'   : 'success_criterion'
    },
   'SC_3_3_5': {
      'title'  : 'sc_3_3_5', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_3_5, 
      'type'   : 'success_criterion'
    },
   'SC_3_3_6': {
      'title'  : 'sc_3_3_6', 
      'option' : OpenAjax.a11y.WCAG20_SUCCESS_CRITERION.SC_3_3_6, 
      'type'   : 'success_criterion'
    },
    
   // Element types 
   'ALL_ELEMENTS': {
      'title'  : 'elementTypeAll', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.ALL, 
      'type'   : 'element'
    },
   'AUDIO_VIDEO_OBJECT_ELEMENTS': {
      'title'  : 'elementTypeAudioVideoObject', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.AUDIO_VIDEO, 
      'type'   : 'element'
    },
   'HEADING_LANDMARK_ELEMENTS': {
      'title'  : 'elementTypeHeadingsLandmarks', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.HEADINGS_LANDMARKS, 
      'type'   : 'element'
    },
   'IMAGE_ELEMENTS': {
      'title'  : 'elementTypeImage', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.IMAGES, 
      'type'   : 'element'
    },
   'FORM_CONTROL_ELEMENTS': {
      'title'  : 'elementTypeFormControls', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.FORM_CONTROLS, 
      'type'   : 'element'
    },
   'LINK_ELEMENTS': {
      'title'  : 'elementTypeLinks', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.LINKS, 
      'type'   : 'element'
    },
   'TABLE_ELEMENTS': {
      'title'  : 'elementTypeLayoutTables', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.LAYOUT_TABLES, 
      'type'   : 'element'
    },
   'TEXT_ELEMENTS': {
      'title'  : 'elementTypeText', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.TEXT, 
      'type'   : 'element'
    },
   'WIDGET_ELEMENTS': {
      'title'  : 'elementTypeWidget', 
      'option' : OpenAjax.a11y.ELEMENT_TYPE.WIDGETS, 
      'type'   : 'element'
    }

};

/**
 * @function OAA_AE_SIDEBAR.rulesetValid
 *
 * @desc Check to make sure their is a valid dom and evaluation
 */

OAA_AE_SIDEBAR.rulesetDocumentValid = function () {

  return (OAA_AE_SIDEBAR.evaluation_result && 
          typeof OAA_AE_SIDEBAR.evaluation_result.doc === "object" &&
          OAA_AE_SIDEBAR.evaluation_result.doc.getElementsByTagName &&
          OAA_AE_SIDEBAR.evaluation_result.doc.getElementsByTagName('body'));

};


/**
 * @function OAA_AE_SIDEBAR.setSidebarView
 *
 * @desc Set the Sidebar View
 */

OAA_AE_SIDEBAR.setSidebarView = function (id) {

  if (typeof id !== 'string') {
    if ((typeof OAA_AE_SIDEBAR.main_window === 'object') && 
        (typeof parent.OAA_AE_TAB === 'object') &&
        (typeof parent.OAA_AE_TAB.last_view_id === 'string')) id = parent.OAA_AE_TAB.last_view_id;
    else id = 'RULE_SUMMARY_CATEGORIES';
  }
  
//  OAA_AE_SIDEBAR.logger.debug("Set View: " + id + " " + OAA_AE_SIDEBAR.OAA_VIEWS[id].option + " " + OAA_AE_SIDEBAR.main_window);

  var view = OAA_AE_SIDEBAR.OAA_VIEWS[id];
  
  parent.OAA_AE_TAB.last_view_id = id;

//  if (typeof OAA_AE_SIDEBAR.main_window === 'object') OAA_AE_SIDEBAR.logger.debug("Last View ID: " + parent.OAA_AE_TAB.last_view_id);

  if (typeof view === 'object') OAA_AE_SIDEBAR.view = view;
  else OAA_AE_SIDEBAR.view = OAA_AE_SIDEBAR.OAA_VIEWS['RULE_SUMMARY_CATEGORIES'];
  
  OAA_AE_SIDEBAR.view.nls_title = OAA_AE_SIDEBAR.nls_strings.getString(OAA_AE_SIDEBAR.view.title);
  
  OAA_AE_SIDEBAR.initSidebarView();
  OAA_AE_SIDEBAR.initSubViewNavigation();
  
  if (typeof OAA_AE_SIDEBAR.evaluation_result !== 'object') {
    OAA_AE_SIDEBAR.updateSidebarData();
  }
  else {    
    OAA_AE_SIDEBAR.updateSidebarView();
  }  
  
//  OAA_AE_SIDEBAR.logger.debug("Update View: End");

};

/**
 * @function OAA_AE_SIDEBAR.initSubViewNavigation
 *
 * @desc Update the sidebar content
 */

OAA_AE_SIDEBAR.initSubViewNavigation = function () {


  var tree = window.document.getElementById('ID_TREE_ELEMENT_VIEW_ITEMS');

  var node = window.document.getElementById('ID_BUTTON_SHOW_RULE_RESULTS');
  if (tree.currentIndex) node.disabled = true;
  node.disabled = false;
  
};
  
/**
 * @function OAA_AE_SIDEBAR.backSidebarView
 *
 * @desc Update the sidebar content
 */

OAA_AE_SIDEBAR.backSidebarView = function() {
  OAA_AE_SIDEBAR.initSidebarView();
  OAA_AE_SIDEBAR.initSubViewNavigation();
  
  var summary_data = null;

  switch (OAA_AE_SIDEBAR.view.type) {

  case 'element':
    OAA_AE_SIDEBAR.ElementView.updateViewNameAndSummary();
    break;

  case 'summary':
  case 'category':
  case 'guideline':
  case 'principle':
  case 'success_criterion':
    summary_data = OAA_AE_SIDEBAR.RuleCategoryView.summary_data;
    OAA_AE_SIDEBAR.setSummaryValues(summary_data);
    break;
    
  default:
    break;
  }

 
};

/**
 * @function OAA_AE_SIDEBAR.updateSidebarView
 *
 * @desc Update the sidebar content
 */

OAA_AE_SIDEBAR.updateSidebarView = function () {

  switch (OAA_AE_SIDEBAR.view.type) {

  case 'element':
    OAA_AE_SIDEBAR.ElementView.update();
    break;

  case 'summary':
  case 'category':
  case 'guideline':
  case 'principle':
  case 'success_criterion':
    OAA_AE_SIDEBAR.RuleCategoryView.update();
    break;
    
  default:
    break;
  }
};


/**
 * @function OAA_AE_SIDEBAR.updateProgress
 *
 * @desc updated progress information on evaluating a document
 */

OAA_AE_SIDEBAR.updateProgress = function (message, percent) {

  if (OAA_AE_SIDEBAR.prog_meter) {
    OAA_AE_SIDEBAR.prog_meter.value = percent;
  }

  if (OAA_AE_SIDEBAR.prog_message) {
    OAA_AE_SIDEBAR.prog_message.value = message;
  }

};

/**
 * @function OAA_AE_SIDEBAR.hideMeter
 *
 * @desc Hides progress bar used to provide information on evaluating a document
 */

OAA_AE_SIDEBAR.hideMeter = function () { 
  OAA_AE_SIDEBAR.meter.hidden = true; 
  OAA_AE_SIDEBAR.evaluate_button.disabled = false; 
};

/**
 * @function OAA_AE_SIDEBAR.showMeter
 *
 * @desc Shows progress bar used to provide information on evaluating a document
 */

OAA_AE_SIDEBAR.showMeter = function () { 
  OAA_AE_SIDEBAR.meter.hidden = false; 
  OAA_AE_SIDEBAR.evaluate_button.disabled = true; 
};

/**
 * @function OAA_AE_SIDEBAR.highlightRemove
 *
 * @desc turn off highlighting for the last cache item that was
 *       highlighted (see highlightCacheItem)
 */

OAA_AE_SIDEBAR.highlightRemove = function () {

  if (OAA_AE_SIDEBAR.rulesetDocumentValid()) {
    OAA_WEB_ACCESSIBILITY.util.highlightModule.removeHighlight(OAA_AE_SIDEBAR.evaluation_result.getDocumentObject());
  }
};

/**
 * highlightCacheItem
 *
 * @desc cache_item Object OAA Cache item
 *
 * @param  {Object}  cache_items  -  cache item object or list of cache item objects
 *
 * @return nothing
 */

OAA_AE_SIDEBAR.highlightCacheItems = function(cache_items) {

  if (OAA_AE_SIDEBAR.rulesetDocumentValid()) {
    OAA_WEB_ACCESSIBILITY.util.highlightModule.highlightCacheItems(OAA_AE_SIDEBAR.evaluation_result.doc, cache_items);
  };  

};

/**
 * highlightNodeResults
 *
 * @desc Highlight a single node result or a list of node results
 *
 * @param {Object or Array} node_results - node result object or an array of node result objects
 *
 * @return nothing
 */

OAA_AE_SIDEBAR.highlightNodeResults = function(node_results) {

  if (OAA_AE_SIDEBAR.rulesetDocumentValid()) {
    OAA_WEB_ACCESSIBILITY.util.highlightModule.highlightNodeResults(OAA_AE_SIDEBAR.evaluation_result.getDocumentObject(), node_results);
  }  

};

/**
 * evaluateDocument
 *
 * @desc opens the log information window
 *
 * @param window Object window object of document to be analyzed
 *
 * @return nothing
 */

OAA_AE_SIDEBAR.evaluateDocument = function () {

//  OAA_AE_SIDEBAR.logger.debug("Evaluating Document: Start");

  var doc;
  var title;
  var url;

  try {
    doc = window.content.document;
    title = doc.title;
    url = window.content.location.href;
  } catch(e) {
    doc  = window.opener.parent.content.document;
    title = doc.title;
    url = window.opener.parent.location.href;
  } // end try
  
  var prefs = OAA_WEB_ACCESSIBILITY_PREF.util.getPreferences();
  
  var emc = prefs.show_results_element_manual_checks;
  var pmc = prefs.show_results_page_manual_checks;
  var wmc = prefs.show_results_website_manual_checks;
  var sp  = prefs.show_results_pass;
  var sh  = prefs.show_results_hidden;

  OAA_AE_SIDEBAR.updateProgress("", 0);

  OpenAjax.a11y.CONSOLE_MESSAGES = true;

  OAA_AE_SIDEBAR.ruleset = OpenAjax.a11y.all_rulesets.getRuleset(prefs.ruleset_id); 
  OAA_WEB_ACCESSIBILITY.util.highlightModule.setHighlightPreferences(emc, (pmc || wmc), sp, sh);

  if (OAA_AE_SIDEBAR.ruleset) {

    OAA_AE_SIDEBAR.ruleset.setEventHandlerProcessor('firefox');
    OAA_AE_SIDEBAR.ruleset.setEvaluationLevels(prefs.evaluation_levels);
    OAA_AE_SIDEBAR.ruleset.setRecommendedRulesEnabled(prefs.recommended_rules_enabled);
    OAA_AE_SIDEBAR.ruleset.setBrokenLinkTesting(prefs.broken_links);
    OAA_AE_SIDEBAR.ruleset.setLayoutTableAssumption(prefs.layout_tables);
  
    OAA_AE_SIDEBAR.logger.debug("Preforming Evaluation: " + title + " " + url);
    OAA_AE_SIDEBAR.logger.debug("           Ruleset ID: " + OAA_AE_SIDEBAR.ruleset.ruleset_id);
    OAA_AE_SIDEBAR.logger.debug("     Evaluation Level: " + OAA_AE_SIDEBAR.ruleset.evaluation_levels);
    OAA_AE_SIDEBAR.logger.debug("         Broken Links: " + OpenAjax.a11y.URL_TESTING_ENABLED);

    OAA_AE_SIDEBAR.evaluation_result = OAA_AE_SIDEBAR.ruleset.evaluate(url, title, doc, OAA_AE_SIDEBAR.updateProgress, true);
  }
  else {
    OAA_AE_SIDEBAR.logger.debug("  ** Ruleset with the id '" + preferences.ruleset_id + "' not found!!");
  }

  OAA_AE.result  = null;
  OAA_AE.log     = null;

  if (OAA_AE && OAA_AE_SIDEBAR.evaluation_result && OAA_AE_SIDEBAR.evaluation_result.result) {
    OAA_AE.result  = OAA_AE_SIDEBAR.evaluation_result.result;
    OAA_AE.log     = OAA_AE_SIDEBAR.evaluation_result.log;
  }

//  OAA_AE_SIDEBAR.logger.debug("Evaluating Document: End");

};

/* ---------------------------------------------------------------- */
/*      Item Properties and Rule Information Dialog Boxes           */ 
/* ---------------------------------------------------------------- */


/**
 * @function OAA_AE_SIDEBAR.showRulePropertiesDialog
 *
 * @desc Show and update information about a rule result for a cache item
 *
 * @param {RuleResult | NodeResult} result_object  -  Rule result or node result object 
 */
 
OAA_AE_SIDEBAR.showRulePropertiesDialog = function (result_object) { 

  if (!OAA_AE_SIDEBAR.rule_properties_dialog || !OAA_AE_SIDEBAR.rule_properties_dialog.rule_properties) {
    if (result_object) OAA_AE_SIDEBAR.rule_properties_dialog = window.openDialog("chrome://oaa-accessibility-extension/content/rule_properties/rule-properties.xul", "_rule_properties_dialog", "", result_object);     
  } else {
    if (result_object && result_object.getRuleSummary) {
      OAA_AE_SIDEBAR.rule_properties_dialog.rule_properties.update(result_object);
      OAA_AE_SIDEBAR.rule_properties_dialog.focus();
    }
    else {
      OAA_AE_SIDEBAR.rule_properties_dialog.rule_properties.clear();    
      OAA_AE_SIDEBAR.rule_properties_dialog.focus();
    }
  }
    
};


/**
 * @function OAA_AE_SIDEBAR.setSummaryValues
 *
 * @desc Update summary information in the sidebar
 *
 * @param {Object} summary_object - Object with summary property
 */
 
OAA_AE_SIDEBAR.setSummaryValues = function (summary_object) { 

  function setResultPercentValue(id, percent, prop) {
  
    var node = document.getElementById(id);
    
    if (node) {
    
       node.setAttribute('value', percent);
       node.setAttribute('class', prop);
       
    }

  }

  function setResultCountValue(id, count, labels, labelp, prop) {
 
    var node_value = document.getElementById((id+"_VALUE"));
    var node_label = document.getElementById((id+"_LABEL"));
    
    if (!node_value || !node_label) return;
    
    var value = 0;
    var style = "zero";
    var label = labelp;
    
    if (typeof count === 'number') {
       value = count;
       
       if (count === 1) label = labels;
       
       if (count === 0) { 
         style = "zero";
         value = "-";
       } 
       else {
         style = prop;
       }  
    }

    node_value.setAttribute('value', value);
    node_value.setAttribute('class', style);
    node_label.setAttribute('value', label);

  }
  
  if (typeof summary_object !== 'object') {
  
    summary_object = new OpenAjax.a11y.RuleResultsSummary();
  
  }
  
  var deck_passed_label = window.document.getElementById('ID_DECK_PASS_LABEL');
  
//  OAA_AE_SIDEBAR.logger.debug("  Percent Passed: " + summary_object.percent_passed + "  Passed: " + summary_object.passed);

  if (summary_object.hasResults()) {
  
    if (typeof summary_object.not_applicable !== 'undefined') {
      setResultCountValue('ID_PASSED', summary_object.passed, 'rule Passed', 'rules Passed', 'passed');  
      deck_passed_label.selectedIndex = 1;
      setResultCountValue('ID_TOTAL_VIOLATIONS',    summary_object.violations,    'rule with Violations',    'rules with Violations',    'violation');  
      setResultCountValue('ID_TOTAL_WARNINGS',      summary_object.warnings,      'rule with Warnings',      'rules with Warnings',      'warning');  
      setResultCountValue('ID_TOTAL_MANUAL_CHECKS', summary_object.manual_checks, 'rule with Manual Checks', 'rules with Manual Checks', 'manual_check');  
    }
    else {
      setResultPercentValue('ID_PASSED_VALUE', summary_object.percent_passed, 'passed');    
      deck_passed_label.selectedIndex = 0;
//      setResultCountValue('ID_PASSED', summary_object.passed, 'Passed', 'Passed', 'passed');  
//      deck_passed_label.selectedIndex = 1;
      setResultCountValue('ID_TOTAL_VIOLATIONS',    summary_object.violations,    'Violation',    'Violations',    'violation');  
      setResultCountValue('ID_TOTAL_WARNINGS',      summary_object.warnings,      'Warning',      'Warnings',      'warning');  
      setResultCountValue('ID_TOTAL_MANUAL_CHECKS', summary_object.manual_checks, 'Manual Check', 'Manual Checks', 'manual_check');  
    }

  }
  else {
    deck_passed_label.selectedIndex = 0;
    document.getElementById('ID_PASSED_VALUE').value              = "-";
    document.getElementById('ID_TOTAL_VIOLATIONS_VALUE').value    = "-";
    document.getElementById('ID_TOTAL_WARNINGS_VALUE').value      = "-";
    document.getElementById('ID_TOTAL_MANUAL_CHECKS_VALUE').value = "-";
  }
  
};    


/**
 * @function OAA_AE_SIDEBAR.showCacheItemPropertiesDialog
 *
 * @desc Builds a button to show and update the node results of a cache item
 *
 * @param {CacheItem} cache_item  -  cache item object
 */
 
OAA_AE_SIDEBAR.showCacheItemPropertiesDialog = function (cache_item) { 

  if (!OAA_AE_SIDEBAR.cache_item_properties_dialog || !OAA_AE_SIDEBAR.cache_item_properties_dialog.cache_item_properties) {
    if (cache_item) OAA_AE_SIDEBAR.cache_item_properties_dialog = window.openDialog("chrome://oaa-accessibility-extension/content/item_properties/cache-item-properties.xul", "_cache_item_properties_dialog", "", cache_item);     
  } else {
    if (cache_item && typeof cache_item.tag_name !== 'undefined') {
      OAA_AE_SIDEBAR.cache_item_properties_dialog.cache_item_properties.update(cache_item);
      OAA_AE_SIDEBAR.cache_item_properties_dialog.focus();
    }
    else {
      OAA_AE_SIDEBAR.cache_item_properties_dialog.cache_item_properties.clear();
    }
  }
  
};


/**
 * @function OAA_AE_SIDEBAR.initSidebarView
 *
 * @desc Initialize sidebar bar information 
 */

OAA_AE_SIDEBAR.initSidebarView = function () {

//  OAA_AE_SIDEBAR.logger.debug("Init Sidebar View: Start");

  if ((typeof OAA_AE_SIDEBAR.view !== 'object') || 
      (OAA_AE_SIDEBAR.view.type === 'undefined')) return;

//  OAA_AE_SIDEBAR.RuleSummaryView.init();

  var node_deck = window.document.getElementById('ID_DECK_VIEW');
  
  var tree;

  switch (OAA_AE_SIDEBAR.view.type) {

  case 'element':
    node_deck.selectedIndex = 2;

    OAA_AE_SIDEBAR.ElementView.updateViewNameAndSummary();
    OAA_AE_SIDEBAR.ElementView.setRuleButtons();
    break;

  case 'summary':
  case 'category':
  case 'guideline':
  case 'principle':
  case 'success_criterion':
    node_deck.selectedIndex = 0;    

    OAA_AE_SIDEBAR.RuleCategoryView.updateViewNameAndSummary();
    OAA_AE_SIDEBAR.RuleCategoryView.setElementButtons();
    break;

  default:
    break;
    
  }

//  OAA_AE_SIDEBAR.logger.debug("Init Sidebar View: End");

};

/**
 * @function OAA_AE_SIDEBAR.clearSidebar
 *
 * @desc Clear sidebar bar information 
 */

OAA_AE_SIDEBAR.clearSidebarView = function () {

//  OAA_AE_SIDEBAR.logger.debug("Clear Sidebar View: Start");

  if ((typeof OAA_AE_SIDEBAR.view !== 'object') || 
      (OAA_AE_SIDEBAR.view.type === 'undefined')) return;
      
  OAA_AE_SIDEBAR.setSummaryValues();     

  switch (OAA_AE_SIDEBAR.view.type) {

  case 'element':
    OAA_AE_SIDEBAR.ElementView.clear();
    break;

  case 'summary':
  case 'category':
  case 'guideline':
  case 'principle':
  case 'success_criterion':
    OAA_AE_SIDEBAR.RuleCategoryView.clear();
    break;

  default:
    break;

  }

//  OAA_AE_SIDEBAR.logger.debug("Clear Sidebar View: end");

};

/**
 * @function OAA_AE_SIDEBAR.updateContext
 *
 * @desc Respond to a locationChange event by calling the showTransition
 *       function for the current sidebar.
 */

OAA_AE_SIDEBAR.updateContext = function () {

//  OAA_AE_SIDEBAR.logger.debug("Tab Select: Start");

  OAA_AE_SIDEBAR.showMeter();
  OAA_AE_SIDEBAR.clearSidebarView();
  OAA_AE_SIDEBAR.updateSidebarData();

//  OAA_AE_SIDEBAR.logger.debug("Tab Select: End");

};

/**
 * @function OAA_AE_SIDEBAR.showTransition
 *
 * @desc Respond to a locationChange event: While new page is loading,
 *       show the progress meter, remove stale data and show message.
 */

OAA_AE_SIDEBAR.showTransition = function () {

  OAA_AE_SIDEBAR.showMeter();
  OAA_AE_SIDEBAR.clearSidebarView();

};

/**
 * @function OAA_AE_SIDEBAR.updateSidebarData
 *
 * @desc Evaluate the new document; hide the progress meter to indicate
 *       loading of the new page has completed; reset isInitialized
 *       variables for all tab panel views so that subsequent calls to
 *       showCacheItems functions result in repopulation with fresh data.
 *       Call showCacheItems for the currently selected tab panel view.
 */

OAA_AE_SIDEBAR.updateSidebarData = function () {

//  OAA_AE_SIDEBAR.logger.debug("Update Sidebar Data: Start");

  OAA_AE_SIDEBAR.evaluateDocument();
  OAA_AE_SIDEBAR.hideMeter();
  OAA_AE_SIDEBAR.updateSidebarView();

//  OAA_AE_SIDEBAR.logger.debug("Update Sidebar Data: End");

};

/**
 * @function OAA_AE_SIDEBAR.onLoad
 *
 * @desc Initialize sidebar and populate its default tabpanel.
 */


OAA_AE_SIDEBAR.setViewsMenu = function() {
  var menuitem = null;

  if (!OAA_AE_SIDEBAR.main_window || !parent.OAA_AE_TAB.last_view_id) return;
  
  var view = {};
  var views = OAA_AE_SIDEBAR.OAA_VIEWS;
  
  var last_view = parent.OAA_AE_TAB.last_view_id;
  
  for (view in views) {
  
    var menu_id = "ID_MENUITEM_VIEW_" + view;
    var node_menuitem = document.getElementById(menu_id);

    // Need to tests since some views may not have a menu item
    if (node_menuitem) {
      if (last_view === view) node_menuitem.setAttribute('checked', 'true'); 
      else node_menuitem.setAttribute('checked', 'false'); 
    }
      
  }

};

/**
 * @function OAA_AE_SIDEBAR.reportCurrentView
 *
 * @desc Create an HTML report based on the current view
 */

OAA_AE_SIDEBAR.reportCurrentView = function () {

  switch (OAA_AE_SIDEBAR.view.type) {

  case 'element':
    OAA_AE_SIDEBAR.createElementReport(parent.OAA_AE_TAB.last_view_id);
    break;

  case 'summary':
  case 'category':
  case 'guideline':
  case 'principle':
  case 'success_criterion':
    OAA_AE_SIDEBAR.createCategoryReport(parent.OAA_AE_TAB.last_view_id);
    break;
    
  default:
    break;
  }
};

/**
 * @function OAA_AE_SIDEBAR.createElementReport
 *
 * @desc Opens a new tab in the window to display an HTML view of the report
 */
 
OAA_AE_SIDEBAR.createElementReport = function (id) {

  var view_info = OAA_AE_SIDEBAR.OAA_VIEWS[id];

  if (!view_info) return;
  
  var title  = OAA_AE_SIDEBAR.nls_strings.getString(view_info.title);
  var option = view_info.option;
  var etr    = null;

  var prefs = OAA_WEB_ACCESSIBILITY_PREF.util.getPreferences();

  if (view_info.type === 'element') etr = OAA_AE_SIDEBAR.evaluation_result.getCacheItemsByElementType(option, prefs.show_results_filter_value); 

  if (!etr) return;

  var dir = FileUtils.getDir('TmpD', [], true, true);

  var file = FileUtils.getFile('TmpD', ['report_element_type.html']);
  
  var fileStream = FileUtils.openSafeFileOutputStream(file, 0x02 | 0x08 | 0x20, 0x644, 0);  
  
  var html = etr.toHTML(title);
  
  fileStream.write(html, html.length);
  
  FileUtils.closeSafeFileOutputStream(fileStream);
    
  OAA_AE_SIDEBAR.main_window.gBrowser.addTab(file.path);


  file = FileUtils.getFile('TmpD', ['report_element_type.csv']);
  
  fileStream = FileUtils.openSafeFileOutputStream(file, 0x02 | 0x08 | 0x20, 0x644, 0);  
  
  var csv = etr.toCSV(title);
  
  fileStream.write(csv, csv.length);
  
  FileUtils.closeSafeFileOutputStream(fileStream);
};


/**
 * @function OAA_AE_SIDEBAR.RuleCategoryView.createReport 
 *
 * @desc Opens a new tab in the window to display an HTML view of the rule category report
 *
 * @param {String}  id  -  The id of the view to show 
 */
 
OAA_AE_SIDEBAR.createCategoryReport = function (id) {

  var view_info = OAA_AE_SIDEBAR.OAA_VIEWS[id];

  if (!view_info) return;
  
  var title  = OAA_AE_SIDEBAR.nls_strings.getString(view_info.title);
  var option = view_info.option;
  var frc    = null;
  
  var prefs = OAA_WEB_ACCESSIBILITY_PREF.util.getPreferences();

  switch (view_info.type) {
  
  case 'summary':
  frc = OAA_AE_SIDEBAR.evaluation_result.getFilteredRuleResultsByRuleSummary(option, prefs.show_results_filter_value);
  break;
  
  case 'category':
  frc = OAA_AE_SIDEBAR.evaluation_result.getFilteredRuleResultsByRuleCategory(option, prefs.show_results_filter_value);
  break;
  
  case 'guideline':
  frc = OAA_AE_SIDEBAR.evaluation_result.getFilteredRuleResultsByGuideline(option, prefs.show_results_filter_value);
  break;

  case 'principle':
  frc = OAA_AE_SIDEBAR.evaluation_result.getFilteredRuleResultsByPrinciple(option, prefs.show_results_filter_value);
  break;

  case 'success_criterion':
  frc = OAA_AE_SIDEBAR.evaluation_result.getFilteredRuleResultsBySuccessCriterion(option, prefs.show_results_filter_value);
  break;


  default:
  break;
  
  }
  
  if (!frc) return;

  // create HTML report file

  var dir = FileUtils.getDir('TmpD', [], true, true);

  var file_html = FileUtils.getFile('TmpD', ['report_rule_category.html']);
  
  var fileStream = FileUtils.openSafeFileOutputStream(file_html, 0x02 | 0x08 | 0x20, 0x644, 0);  
  
  var html = frc.toHTML(title);
  
  fileStream.write(html, html.length);
  
  FileUtils.closeSafeFileOutputStream(fileStream);
    
  // create CSV file

  file_csv = FileUtils.getFile('TmpD', ['report_rule_category.csv']);
  
  fileStream = FileUtils.openSafeFileOutputStream(file_csv, 0x02 | 0x08 | 0x20, 0x644, 0);  
  
  var csv = frc.toCSV(title);
  
  fileStream.write(csv, csv.length);
  
  FileUtils.closeSafeFileOutputStream(fileStream);

  OAA_AE_SIDEBAR.logger.debug("CSV File: " + file_csv.path);

  OAA_AE_SIDEBAR.main_window.gBrowser.addTab(file_html.path);


};

/**
 * @function OAA_AE_SIDEBAR.preferencesDialog
 *
 * @desc Opens the preferences dialog box
 */

OAA_AE_SIDEBAR.preferencesDialog = function () {

  window.openDialog('chrome://oaa-accessibility-extension/content/preferences-dialog.xul', "_cache_inspector_preferences_dialog", "", parent.OAA_AE_TAB.preferences_callback); 
  
};

/**
 * @function OAA_AE_SIDEBAR.init
 *
 * @desc Initialize event listners
 */

OAA_AE_SIDEBAR.init = function () {

  // set default value for view
  if (typeof parent.OAA_AE_TAB !== 'object') parent.OAA_AE_TAB = {};

  // set default value for view
  if (typeof parent.OAA_AE_TAB.last_view_id !== 'string') parent.OAA_AE_TAB.last_view_id = 'ALL_RULES';

  // get mainWindow for this sidebar
  OAA_AE_SIDEBAR.main_window = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    .getInterface(Components.interfaces.nsIWebNavigation)
    .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
    .rootTreeItem
    .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    .getInterface(Components.interfaces.nsIDOMWindow);

  OAA_AE_SIDEBAR.nls_strings = document.getElementById('ID_STRINGBUNDLE_LIST');

  // get tabbrowser
  OAA_AE_SIDEBAR.tabbrowser = OAA_AE_SIDEBAR.main_window.gBrowser;

  // instantiate progressListener

  // load script with progressListener factory method
  Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
    .getService(Components.interfaces.mozIJSSubScriptLoader)
    .loadSubScript("resource://oaa-ae-utilities/progress.js", OAA_AE_SIDEBAR);

  // instantiate progressListener
  OAA_AE_SIDEBAR.progressListener = OAA_AE_SIDEBAR.getProgressListener(
    OAA_AE_SIDEBAR.showTransition,
    OAA_AE_SIDEBAR.updateSidebarData);

  // add required listeners
  parent.gBrowser.addProgressListener(OAA_AE_SIDEBAR.progressListener);

  };

OAA_AE_SIDEBAR.init();


/**
 * @function OAA_AE_SIDEBAR.onLoad
 *
 * @desc Initialize sidebar and populate its default tabpanel.
 */

OAA_AE_SIDEBAR.onLoad = function () {

  // Get Library

  // Enable console messaging
  OpenAjax.a11y.setLogger(OAA_AE_SIDEBAR.getLogger("OAA-LIB", false));
  OpenAjax.a11y.logger.enabled = true; 
  OpenAjax.a11y.logger.level   = OpenAjax.a11y.logger.LEVEL.DEBUG; 
  
  OAA_AE_SIDEBAR.logger = OAA_AE_SIDEBAR.getLogger("OAA-AE SIDEBAR", true);

  OAA_AE_SIDEBAR.initRuleInformation();

  OAA_AE_SIDEBAR.main_window.gBrowser.addProgressListener(OAA_AE_SIDEBAR.progressListener);

  OAA_AE_SIDEBAR.oaa_log_window = null;
  OAA_AE_SIDEBAR.oaa_results_window = null;

  OAA_AE_SIDEBAR.meter           = document.getElementById('ID_PROGRESS_METER');
  OAA_AE_SIDEBAR.evaluate_button = document.getElementById('ID_BUTTON_EVALUATE');

  // register with current tab
  OAA_AE_SIDEBAR.tabbrowser.selectedTab.setAttribute(OAA_AE.TAB_ATTRIBUTE_NAME, "true");

  // register callback for tab selection
  parent.OAA_AE_TAB.updateContext = OAA_AE_SIDEBAR.updateContext;

//  OAA_AE_SIDEBAR.logger.debug("Evaluate Button: " + OAA_AE_SIDEBAR.evaluate_button);  

  // Preferences needs to be a global variable on the window for a call back function
  parent.OAA_AE_TAB.preferences_callback = function () {
      OAA_AE_SIDEBAR.updateSidebarData();  
  };

  OAA_WEB_ACCESSIBILITY.util.highlightModule.initHighlight();
  
  OAA_AE_SIDEBAR.initRulesetOptions();

  OAA_AE_SIDEBAR.setSidebarView();

};

/**
 * @function OAA_AE_SIDEBAR.onUnload
 *
 * @desc onunLoad event handler that resets object properties
 *
 * @return nothing
 */

OAA_AE_SIDEBAR.onUnload = function(cache) {

  OAA_AE_SIDEBAR.highlightRemove();
  
  OAA_AE_SIDEBAR.main_window.gBrowser.removeProgressListener(OAA_AE_SIDEBAR.progressListener);

  // unregister with current tab
  OAA_AE_SIDEBAR.tabbrowser.selectedTab.removeAttribute(OAA_AE.TAB_ATTRIBUTE_NAME);

  if (OAA_AE_SIDEBAR.cache_item_properties_dialog && 
      OAA_AE_SIDEBAR.cache_item_properties_dialog.cache_item_properties) {
    OAA_AE_SIDEBAR.cache_item_properties_dialog.close();
  }

  if (OAA_AE_SIDEBAR.rule_properties_dialog && OAA_AE_SIDEBAR.rule_properties_dialog.rule_properties) {
    OAA_AE_SIDEBAR.rule_properties_dialog.close();
  }  
  
  parent.OAA_AE_TAB.preferences_callback = null;
    
};

window.addEventListener("load",   OAA_AE_SIDEBAR.onLoad, false);
window.addEventListener("unload", OAA_AE_SIDEBAR.onUnload, false);
